package pl.register.android.util.builders.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import pl.register.android.R;

/**
 * @author Mateusz Strzelecki
 * @since 2013-04-12
 */
public abstract class AbstractInputDialogBuilder<T> extends AlertDialog.Builder {

    private EditText etInput;

    private Button positiveBtn;

    public AbstractInputDialogBuilder(Context context) {
        super(context);
        onCreateContent(context);
    }

    private void onCreateContent(Context ctx) {
        LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(ctx.LAYOUT_INFLATER_SERVICE);
        View dialogLayout = inflater.inflate(R.layout.dialog_input_layout, null);
        etInput = (EditText) dialogLayout.findViewById(R.id.input_edit_text);

        setView(dialogLayout);
    }

    protected AlertDialog create(T editedObject) {
        AlertDialog alertDialog = super.create();
        positiveBtn = alertDialog.getButton(Dialog.BUTTON1);
        return alertDialog;
    }

    protected void setInputText(String string) {
        etInput.setText(string);
    }

    protected String getInputText() {
        return etInput.getText().toString();
    }

}